<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.com">
<head>
    <meta charset="UTF-8">
    <title>商品信息修改</title>
    <link rel="stylesheet" href="/css/admin.css">
    <style type="text/css">
        .frm {
            width: 600px;
            margin: 30px auto;
        }
    </style>
    <script type="text/javascript">
        // 文件框选择图片时，图片标签自动切换
        function showImg() {
            var f = new FileReader();
            f.onload = function (ev) {
                img.src = ev.target.result;
            }
            f.readAsDataURL(file.files[0]);
        }
    </script>
</head>
<body>
<div class="frm">
    <div class="title">商品信息修改</div>
    <form action="/admin/goods/update_submit" method="post" enctype="multipart/form-data">
        <input type="hidden" name="goodsId" th:value="${goods.goodsId}"/> >
        <table>
            <tr>
                <td>商品名称</td>
                <td>
                    <label>
                        <input type="text" name="goodsName" required="required" th:value="${goods.goodsName}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>价格</td>
                <td>
                    <label>
                        <input type="number" name="price" required="required" th:value="${goods.price}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>产地</td>
                <td>
                    <label>
                        <input type="text" name="address" required="required" th:value="${goods.address}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>生产日期</td>
                <td>
                    <label>
                        <input type="date" name="produceDate" required="required"
                               th:value="${#dates.format(goods.produceDate,'yyyy-MM-dd')}"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>产品图片</td>
                <td>
                    <img th:src="${goods.picture}" width="80" height="100" id="img"/>
                    <br/>
                    <input type="file" name="file" id="file" onchange="showImg()"/>
                    <input type="hidden" name="picture" th:value="${goods.picture}"/>
                </td>
            </tr>
            <tr>
                <td>商品分类</td>
                <td>
                    <label>
                        <select name="category.categoryId">
                            <option value="">请选择</option>
                            <option th:each="c:${categoryList}"
                                    th:value="${c.categoryId}"
                                    th:text="${c.categoryName}"
                                    th:selected="${c.categoryId==goods.category.categoryId}">
                            </option>
                        </select>
                    </label>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" name="修改"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>